import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
import _applyDecoratedDescriptor from "@babel/runtime/helpers/esm/applyDecoratedDescriptor";
import _isEmpty from "lodash/isEmpty";
import _isArray from "lodash/isArray";
import _cloneDeep from "lodash/cloneDeep";
var _excluded = ["searchDocTypeName"],
    _excluded2 = ["roleAuthorityLines", "msgFlag"];

var _dec, _dec2, _dec3, _dec4, _dec5, _dec6, _dec7, _dec8, _dec9, _dec10, _dec11, _dec12, _dec13, _dec14, _class, _class2;

import React from 'react';
import { Button, Checkbox as OriginCheckbox, Col, Form, Input, Modal, // Radio,
Row, Table, Tabs } from 'antd';
import { Bind } from 'lodash-decorators'; // import uuid from 'uuid/v4';

import Checkbox from 'components/Checkbox';
import intl from 'utils/intl';
import formatterCollections from 'utils/intl/formatterCollections';
import { createPagination, isTenantRoleLevel, tableScrollWidth } from 'utils/utils';
import { SEARCH_FORM_ITEM_LAYOUT } from 'utils/constants';
import AuthData from "./AuthData";
import styles from "../index.less?modules";
var CheckboxGroup = OriginCheckbox.Group; // const RadioGroup = Radio.Group;

var AuthDrawer = (_dec = formatterCollections({
  code: ['ciam.roleManagement', 'entity.tenant']
}), _dec2 = Form.create({
  fieldNameProp: null
}), _dec3 = Bind(), _dec4 = Bind(), _dec5 = Bind(), _dec6 = Bind(), _dec7 = Bind(), _dec8 = Bind(), _dec9 = Bind(), _dec10 = Bind(), _dec11 = Bind(), _dec12 = Bind(), _dec13 = Bind(), _dec14 = Bind(), _dec(_class = _dec2(_class = (_class2 = /*#__PURE__*/function (_React$Component) {
  _inherits(AuthDrawer, _React$Component);

  var _super = _createSuper(AuthDrawer);

  function AuthDrawer(props) {
    var _this;

    _classCallCheck(this, AuthDrawer);

    _this = _super.call(this, props);
    var _props$roleAuth = props.roleAuth,
        roleAuth = _props$roleAuth === void 0 ? {} : _props$roleAuth,
        _props$roleAuth$conte = props.roleAuth.content,
        content = _props$roleAuth$conte === void 0 ? [] : _props$roleAuth$conte,
        _props$roleAuthScopeC = props.roleAuthScopeCode,
        roleAuthScopeCode = _props$roleAuthScopeC === void 0 ? [] : _props$roleAuthScopeC,
        _props$roleAuthScopeT = props.roleAuthScopeTypeCode,
        roleAuthScopeTypeCode = _props$roleAuthScopeT === void 0 ? [] : _props$roleAuthScopeT;
    var selectedRowKeys = content.filter(function (item) {
      return !!item.docEnabledFlag;
    }).map(function (item) {
      return item.authDocTypeId;
    });
    _this.state = {
      currentAuthScope: null,
      // 当前选中的范围
      authUserDefaultValue: [],
      // 数据为用户范围时的选中值
      selectedRow: {},
      // 选中的单据行数据
      selectedRowKeys: selectedRowKeys,
      // 选择项
      key: 'uuid',
      // 单据主键
      roleAuth: roleAuth,
      content: [],
      roleAuthScopeCode: roleAuthScopeCode,
      roleAuthScopeTypeCode: roleAuthScopeTypeCode,
      authDefaultValue: [],
      // 权限维度默认选中的列表
      enableChangeList: [],
      msgChangeList: [],
      scopeChangeList: [],
      authChangeList: [],
      isSiteFlag: !isTenantRoleLevel()
    };
    return _this;
  }

  _createClass(AuthDrawer, [{
    key: "handleCancel",
    value: function handleCancel() {
      var _this$props$onCancel = this.props.onCancel,
          onCancel = _this$props$onCancel === void 0 ? function (e) {
        return e;
      } : _this$props$onCancel;
      onCancel(this.resetState);
    }
  }, {
    key: "handleOk",
    value: function handleOk() {
      var _this2 = this;

      var _this$props = this.props,
          form = _this$props.form,
          _this$props$onOk = _this$props.onOk,
          onOk = _this$props$onOk === void 0 ? function (e) {
        return e;
      } : _this$props$onOk;
      var _this$state = this.state,
          scopeChangeList = _this$state.scopeChangeList,
          authChangeList = _this$state.authChangeList,
          enableChangeList = _this$state.enableChangeList;
      form.validateFields(function (err, fieldsValue) {
        var searchDocTypeName = fieldsValue.searchDocTypeName,
            msgFlags = _objectWithoutProperties(fieldsValue, _excluded);

        var checkedList = Object.keys(msgFlags).filter(function (item) {
          return !!msgFlags[item];
        }).map(function (item) {
          return item.split('#')[0] * 1;
        });
        var _this2$state = _this2.state,
            key = _this2$state.key,
            _this2$state$content = _this2$state.content,
            content = _this2$state$content === void 0 ? [] : _this2$state$content;

        var dataClone = _cloneDeep(content);

        var currentEnableChangeList = dataClone.filter(function (item) {
          return item.docEnabledFlag ? false : item.authControlType === 'ONLY_CONFIG';
        });
        var newMsgChangeList = dataClone.filter(function (item) {
          return !!item.docEnabledFlag && item.msgFlag ? checkedList.findIndex(function (e) {
            return e === item[key];
          }) === -1 : checkedList.findIndex(function (e) {
            return e === item[key];
          }) !== -1;
        }).map(function (item) {
          delete item.roleAuthorityLines; // eslint-disable-line

          return _objectSpread(_objectSpread({}, item), {}, {
            msgFlag: !item.msgFlag ? 1 : 0
          });
        });

        var data = _this2.createSaveData([].concat(_toConsumableArray(currentEnableChangeList), _toConsumableArray(enableChangeList)), newMsgChangeList, scopeChangeList, authChangeList);

        onOk(data, _this2.resetState); // this.resetState();
      });
    }
  }, {
    key: "onRow",
    value: function onRow(record) {
      var _record$roleAuthority = record.roleAuthorityLines,
          roleAuthorityLines = _record$roleAuthority === void 0 ? [] : _record$roleAuthority;
      var authDefaultValue = [];

      if (roleAuthorityLines) {
        authDefaultValue = roleAuthorityLines.filter(function (item) {
          return !!item.enabledFlag;
        }).map(function (item) {
          return item.authDimId;
        });
      }

      var authUserDefaultValue = roleAuthorityLines && [roleAuthorityLines.filter(function (item) {
        return item.dimensionType === 'USER' && !!item.enabledFlag;
      }).map(function (item) {
        return item.authDimId;
      })[0]] || [];
      this.setState({
        authDefaultValue: authDefaultValue,
        authUserDefaultValue: authUserDefaultValue,
        selectedRow: record,
        currentAuthScope: record.authScopeCode
      });
    }
    /**
     * 为当前点击行添加 class
     * @param {Object} record - 行数据
     */

  }, {
    key: "addHighlight",
    value: function addHighlight(record) {
      var selectedRow = this.state.selectedRow;
      return record.uuid === selectedRow.uuid ? styles['auth-row-hover'] : '';
    }
    /**
     * 勾选单据项列表时，添加或删除单据项
     * @param {*} selectedRowKeys - 选中的单据项列表
     */
    // @Bind()
    // onSelectChange(rowkeys = []) {
    //   const {
    //     key,
    //     enableChangeList = [],
    //     roleAuth: { content = [] },
    //   } = this.state;
    //   const otherEnableChangeList = differenceBy(enableChangeList, content, 'authDocTypeId'); // 其他页面改变启用的单据列表
    //   const dataClone = cloneDeep(content);
    //   const currentEnableChangeList = dataClone
    //     .filter(item =>
    //       item.docEnabledFlag
    //         ? rowkeys.findIndex(e => e === item[key]) === -1
    //         : rowkeys.findIndex(e => e === item[key]) !== -1
    //     )
    //     .map(item => ({
    //       ...item,
    //       docEnabledFlag: item.docEnabledFlag ? 0 : 1,
    //     }));
    //   this.setState({
    //     enableChangeList: [...otherEnableChangeList, ...currentEnableChangeList],
    //   });
    // }

  }, {
    key: "handleSearch",
    value: function handleSearch() {
      this.handlePagination();
    }
  }, {
    key: "handlePagination",
    value: function handlePagination(pagination) {
      var _this$props2 = this.props,
          form = _this$props2.form,
          _this$props2$handleQu = _this$props2.handleQuery,
          handleQuery = _this$props2$handleQu === void 0 ? function (e) {
        return e;
      } : _this$props2$handleQu;
      var params = {
        page: pagination ? pagination.current - 1 : 0,
        size: pagination ? pagination.pageSize : 10,
        docTypeName: form.getFieldValue('searchDocTypeName')
      };
      handleQuery(params);
    } // @Bind()
    // handleDelete() {
    //   const { handleDelete = e => e } = this.props;
    //   const { selectedRow } = this.state;
    //   handleDelete(selectedRow);
    // }

  }, {
    key: "resetState",
    value: function resetState() {
      this.setState({
        currentAuthScope: null,
        // 当前选中的范围
        authUserDefaultValue: [],
        // 用户范围下当前选中
        selectedRow: {},
        // 选中的单据行数据
        roleAuth: {},
        roleAuthScopeCode: null,
        roleAuthScopeTypeCode: null,
        authDefaultValue: [],
        enableChangeList: [],
        msgChangeList: [],
        scopeChangeList: [],
        authChangeList: []
      });
    }
    /**
     * 消息发送变更事件
     * @param {Array} checkedList - 消息发送标志启用列表
     */
    // @Bind()
    // msgOnChange() {
    //   const { form } = this.props;
    //   form.validateFields((err, fieldsValue) => {
    //     const { searchDocTypeName, ...msgFlags } = fieldsValue;
    //     const checkedList = Object.keys(msgFlags)
    //       .filter(item => !!msgFlags[item])
    //       .map(item => item.split('#')[0] * 1);
    //     const {
    //       roleAuth: { content = [] },
    //       key,
    //       selectedRow,
    //     } = this.state;
    //     const dataClone = cloneDeep(content);
    //     const newMsgChangeList = dataClone
    //       .filter(item =>
    //         !!item.docEnabledFlag && item.msgFlag
    //           ? checkedList.findIndex(e => e === item[key]) === -1
    //           : checkedList.findIndex(e => e === item[key]) !== -1
    //       )
    //       .map(item => {
    //         delete item.roleAuthorityLines; // eslint-disable-line
    //         return {
    //           ...item,
    //           msgFlag: !item.msgFlag ? 1 : 0,
    //         };
    //       });
    //     this.setState({
    //       msgChangeList: newMsgChangeList,
    //     });
    //     const index = newMsgChangeList.findIndex(item => item[key] === selectedRow[key]);
    //     if (index !== -1) {
    //       this.setState({
    //         selectedRow: {
    //           ...selectedRow,
    //           msgFlag: newMsgChangeList[index].msgFlag,
    //         },
    //       });
    //     }
    //   });
    // }

    /* eslint-disable no-param-reassign */

    /**
     * 延迟 onChange 事件执行，解决先于 onRow 事件执行问题
     * @param {Object} e - RadioGroup Change 事件
     */

  }, {
    key: "scopeOnChangeLater",
    value: function scopeOnChangeLater(e) {
      var _this3 = this;

      setTimeout(function () {
        _this3.scopeOnChange(e);
      }, 0); // if(!e.target.checked) {
      //   this.setState({
      //     selectedRow: [],
      //   });
      // }
    }
    /**
     * 权限范围类型变更事件
     * @param {Object} e - 变更事件对象
     */

  }, {
    key: "scopeOnChange",
    value: function scopeOnChange(e) {
      var _this$state2 = this.state,
          selectedRow = _this$state2.selectedRow,
          _this$state2$scopeCha = _this$state2.scopeChangeList,
          scopeChangeList = _this$state2$scopeCha === void 0 ? [] : _this$state2$scopeCha,
          key = _this$state2.key,
          _this$state2$content = _this$state2.content,
          content = _this$state2$content === void 0 ? [] : _this$state2$content;

      var dataClone = _cloneDeep(content);

      var newScopeChangeList = _cloneDeep(scopeChangeList);

      var sourceRow = dataClone.find(function (item) {
        return item[key] === selectedRow[key];
      }); // 找到原始单据项

      var index = scopeChangeList.findIndex(function (item) {
        return item[key] === selectedRow[key];
      }); // eslint-disable-next-line no-constant-condition
      // if (e.target.checked) {

      if (index !== -1) {
        if (e && e.target && sourceRow.docEnabledFlag !== e.target.checked) {
          newScopeChangeList.splice(index, 1, _objectSpread(_objectSpread({}, newScopeChangeList[index]), {}, {
            docEnabledFlag: e.target.checked
          }));
          this.setState({
            scopeChangeList: newScopeChangeList.map(function (item) {
              delete item.msgFlag;
              delete item.roleAuthorityLines;
              return item;
            })
          });
        } else {
          newScopeChangeList.splice(index, 1);
          this.setState({
            scopeChangeList: newScopeChangeList.map(function (item) {
              delete item.msgFlag;
              delete item.roleAuthorityLines;
              return item;
            })
          });
        }
      } else {
        this.setState({
          scopeChangeList: [].concat(_toConsumableArray(scopeChangeList), [_objectSpread(_objectSpread({}, sourceRow), {}, {
            docEnabledFlag: e.target.checked
          })]).map(function (item) {
            delete item.msgFlag;
            delete item.roleAuthorityLines;
            return item;
          })
        });
      } // } else if (index !== -1) {
      //   newScopeChangeList.splice(index, 1);
      //   this.setState({
      //     scopeChangeList: newScopeChangeList.map(item => {
      //       delete item.msgFlag;
      //       delete item.roleAuthorityLines;
      //       return item;
      //     }),
      //   });
      // }


      if (e.target.checked === 0) {
        if (selectedRow.authScopeCode === 'USER') {
          this.authOnChange({});
        } else {
          this.authOnChange([]);
        }
      }

      this.setState({
        currentAuthScope: selectedRow.authScopeCode,
        selectedRow: _objectSpread(_objectSpread({}, selectedRow), {}, {
          docEnabledFlag: e.target.checked
        })
      }); // 未选中的时候， 不显示权限值
      // if(!e.target.checked) {
      //   this.onRow(selectedRow);
      //   this.setState({
      //     selectedRow: [],
      //   });
      // }
    }
    /**
     * 权限维度变更事件
     * @param {Array} checkedList - 选中的权限项列表
     */

  }, {
    key: "authOnChange",
    value: function authOnChange(checkedList) {
      var _this$state3 = this.state,
          selectedRow = _this$state3.selectedRow,
          _this$state3$authChan = _this$state3.authChangeList,
          authChangeList = _this$state3$authChan === void 0 ? [] : _this$state3$authChan,
          key = _this$state3.key,
          _this$state3$content = _this$state3.content,
          content = _this$state3$content === void 0 ? [] : _this$state3$content;

      var dataClone = _cloneDeep(content);

      var newAuthChangeList = _cloneDeep(authChangeList);

      var sourceRow = dataClone.find(function (item) {
        return item[key] === selectedRow[key];
      }) || []; // 找到原始单据项

      var sourceList = sourceRow.roleAuthorityLines || []; // 查找原始 List

      var editRow;

      if (_isArray(checkedList)) {
        editRow = _objectSpread(_objectSpread({}, sourceRow), {}, {
          roleAuthorityLines: !_isEmpty(checkedList) ? sourceList.filter(function (item) {
            return item.enabledFlag ? checkedList.findIndex(function (e) {
              return e === item.authDimId;
            }) === -1 : checkedList.findIndex(function (e) {
              return e === item.authDimId;
            }) !== -1;
          }).map(function (item) {
            return _objectSpread(_objectSpread({}, item), {}, {
              enabledFlag: !item.enabledFlag ? 1 : 0
            });
          }) : sourceList.map(function (i) {
            return _objectSpread(_objectSpread({}, i), {}, {
              enabledFlag: 0
            });
          })
        }); // 将变更过的权限列表项添加
      } else {
        editRow = _objectSpread(_objectSpread({}, sourceRow), {}, {
          roleAuthorityLines: !_isEmpty(checkedList) ? sourceList.filter(function (item) {
            return item.authDimId === checkedList.authDimId;
          }).map(function (item) {
            return _objectSpread(_objectSpread({}, item), {}, {
              enabledFlag: 1
            });
          }) : sourceList.filter(function (item) {
            return !!item.enabledFlag;
          }).map(function (i) {
            return _objectSpread(_objectSpread({}, i), {}, {
              enabledFlag: 0
            });
          })
        });
      }

      var index = authChangeList.findIndex(function (item) {
        return item[key] === editRow[key];
      });

      if (_isEmpty(editRow.roleAuthorityLines)) {
        if (index !== -1) {
          newAuthChangeList.splice(index, 1);
          this.setState({
            authChangeList: newAuthChangeList.map(function (item) {
              delete item.msgFlag;
              return item;
            })
          });
        }
      } else if (index !== -1) {
        newAuthChangeList.splice(index, 1, editRow);
        this.setState({
          authChangeList: newAuthChangeList.map(function (item) {
            delete item.msgFlag;
            return item;
          })
        });
      } else {
        this.setState({
          authChangeList: [].concat(_toConsumableArray(newAuthChangeList), [editRow]).map(function (item) {
            delete item.msgFlag;
            return item;
          })
        });
      }

      if (!_isEmpty(checkedList)) {
        this.scopeOnChange({
          target: {
            checked: 1
          }
        });
      }

      if (!_isArray(checkedList)) {
        this.setState({
          authUserDefaultValue: checkedList ? [checkedList.authDimId] : []
        });
      } else {
        this.setState({
          authDefaultValue: checkedList
        });
      } // 选择权限维度项时触发范围修改


      if (!_isArray(checkedList)) {
        var currentAuthScope = this.state.currentAuthScope;

        if (currentAuthScope !== 'USER') {
          var params = {
            target: {
              value: 'USER'
            }
          };
          this.scopeOnChange(params);
        }
      } else {
        var _currentAuthScope = this.state.currentAuthScope;

        if (_currentAuthScope !== 'BIZ') {
          var _params = {
            target: {
              value: 'BIZ'
            }
          };
          this.scopeOnChange(_params);
        }
      }

      var roleAuthorityLines = selectedRow.roleAuthorityLines;
      var newList = roleAuthorityLines || [];
      this.setState({
        selectedRow: _objectSpread(_objectSpread({}, selectedRow), {}, {
          roleAuthorityLines: newList.map(function (item) {
            var idx = editRow.roleAuthorityLines.findIndex(function (e) {
              return e.authDimId === item.authDimId;
            });

            if (idx !== -1) {
              return _objectSpread(_objectSpread({}, item), {}, {
                enabledFlag: editRow.roleAuthorityLines[idx].enabledFlag
              });
            } else {
              return item;
            }
          })
        })
      });
    }
    /**
     * 合并数据进行展示
     * @param {Array} sourceData - 原始数据
     * @param {Array} msgChangeList - 消息发送标志变化的数据
     * @param {Array} scopeChangeList - 权限范围变化的数据
     * @param {Array} authChangeList - 权限维度变化的数据
     */

  }, {
    key: "mergeData",
    value: function mergeData() {
      var sourceData = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
      var enableChangeList = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
      var msgChangeList = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
      var scopeChangeList = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
      var authChangeList = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : [];
      var key = this.state.key;
      var data = sourceData.map(function (item) {
        var enableIndex = enableChangeList.findIndex(function (e) {
          return e[key] === item[key];
        });
        var msgIndex = msgChangeList.findIndex(function (e) {
          return e[key] === item[key];
        });
        var scopeIndex = scopeChangeList.findIndex(function (e) {
          return e[key] === item[key];
        });
        var authIndex = authChangeList.findIndex(function (e) {
          return e[key] === item[key];
        });

        var newRoleAuthorityLines = _cloneDeep(item.roleAuthorityLines);

        if (authIndex !== -1) {
          var changeList = authChangeList[authIndex].roleAuthorityLines;
          changeList.forEach(function (e) {
            var index = newRoleAuthorityLines.findIndex(function (line) {
              return line.authDimId === e.authDimId;
            });
            newRoleAuthorityLines.splice(index, 1, e);
          });
        }

        return _objectSpread(_objectSpread({}, item), {}, {
          docEnabledFlag: enableIndex !== -1 ? enableChangeList[enableIndex].docEnabledFlag : item.docEnabledFlag,
          msgFlag: msgIndex !== -1 ? msgChangeList[msgIndex].msgFlag : item.msgFlag,
          authScopeCode: scopeIndex !== -1 ? scopeChangeList[scopeIndex].authScopeCode : item.authScopeCode,
          roleAuthorityLines: newRoleAuthorityLines
        });
      });
      return data;
    }
  }, {
    key: "createSaveData",
    value: function createSaveData() {
      var enableChangeList = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
      var msgChangeList = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
      var scopeChangeList = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
      var authChangeList = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
      var key = this.state.key;
      var newEnableChangeList = enableChangeList.map(function (item) {
        var roleAuthorityLines = item.roleAuthorityLines,
            msgFlag = item.msgFlag,
            other = _objectWithoutProperties(item, _excluded2);

        return _objectSpread({}, other);
      });

      var saveList = _toConsumableArray(newEnableChangeList);

      msgChangeList.forEach(function (item) {
        var index = saveList.findIndex(function (e) {
          return e[key] === item[key];
        });

        if (index !== -1) {
          saveList.splice(index, 1, _objectSpread(_objectSpread({}, saveList[index]), {}, {
            msgFlag: item.msgFlag
          }));
        } else {
          saveList.push(item);
        }
      });
      scopeChangeList.forEach(function (item) {
        var index = saveList.findIndex(function (e) {
          return e[key] === item[key];
        });

        if (index !== -1) {
          saveList.splice(index, 1, _objectSpread(_objectSpread({}, saveList[index]), {}, {
            authScopeCode: item.authScopeCode
          }));
        } else {
          saveList.push(item);
        }
      });
      authChangeList.forEach(function (item) {
        var index = saveList.findIndex(function (e) {
          return e[key] === item[key];
        });

        if (index !== -1) {
          saveList.splice(index, 1, _objectSpread(_objectSpread({}, saveList[index]), {}, {
            roleAuthorityLines: item.roleAuthorityLines
          }));
        } else {
          saveList.push(item);
        }
      });
      return saveList.map(function (item) {
        var auths = item.roleAuthorityLines || []; // 判断是否具备 auth 变更

        return _isArray(item.roleAuthorityLines) ? _objectSpread(_objectSpread({}, item), {}, {
          roleAuthorityLines: auths.filter(function (e) {
            return !!e.authDimId;
          }) // 过滤非修改权限范围类型内的权限维度以及未启用的权限维度

        }) : item;
      }).filter(function (item) {
        return !(_isArray(item.roleAuthorityLines) && _isEmpty(item.roleAuthorityLines));
      });
    }
  }, {
    key: "render",
    value: function render() {
      var _this4 = this;

      var _this$props3 = this.props,
          dispatch = _this$props3.dispatch,
          path = _this$props3.path,
          form = _this$props3.form,
          saveLoading = _this$props3.saveLoading,
          initLoading = _this$props3.initLoading,
          title = _this$props3.title,
          modalVisible = _this$props3.modalVisible,
          roleId = _this$props3.roleId,
          tenantId = _this$props3.tenantId,
          roleDataAuthorityCompany = _this$props3.roleDataAuthorityCompany,
          roleDataAuthorityPurorg = _this$props3.roleDataAuthorityPurorg,
          roleDataAuthorityManagement = _this$props3.roleDataAuthorityManagement,
          _this$props3$roleData = _this$props3.roleDataAuthorityPuragent,
          roleDataAuthorityPuragent = _this$props3$roleData === void 0 ? {} : _this$props3$roleData,
          _this$props3$roleData2 = _this$props3.roleDataAuthorityLovView,
          roleDataAuthorityLovView = _this$props3$roleData2 === void 0 ? {} : _this$props3$roleData2,
          _this$props3$roleData3 = _this$props3.roleDataAuthorityDataSource,
          roleDataAuthorityDataSource = _this$props3$roleData3 === void 0 ? {} : _this$props3$roleData3,
          _this$props3$roleData4 = _this$props3.roleDataAuthorityValueList,
          roleDataAuthorityValueList = _this$props3$roleData4 === void 0 ? {} : _this$props3$roleData4,
          _this$props3$roleData5 = _this$props3.roleDataAuthorityDataGroup,
          roleDataAuthorityDataGroup = _this$props3$roleData5 === void 0 ? {} : _this$props3$roleData5,
          fetchTabListLoading = _this$props3.fetchTabListLoading,
          updateCompanyLoading = _this$props3.updateCompanyLoading,
          fetchCompanyLoading = _this$props3.fetchCompanyLoading,
          refreshCompanyLoading = _this$props3.refreshCompanyLoading,
          addPurOrgLoading = _this$props3.addPurOrgLoading,
          fetchPurOrgLoading = _this$props3.fetchPurOrgLoading,
          fetchPurOrgModalLoading = _this$props3.fetchPurOrgModalLoading,
          addPuragentLoading = _this$props3.addPuragentLoading,
          fetchPuragentLoading = _this$props3.fetchPuragentLoading,
          fetchModalPuragentLoading = _this$props3.fetchModalPuragentLoading,
          addValueListLoading = _this$props3.addValueListLoading,
          fetchValueListLoading = _this$props3.fetchValueListLoading,
          fetchModalValueListLoading = _this$props3.fetchModalValueListLoading,
          addLovViewLoading = _this$props3.addLovViewLoading,
          fetchLovViewLoading = _this$props3.fetchLovViewLoading,
          fetchModalLovViewLoading = _this$props3.fetchModalLovViewLoading,
          addDataSourceLoading = _this$props3.addDataSourceLoading,
          fetchDataSourceLoading = _this$props3.fetchDataSourceLoading,
          fetchModalDataSourceLoading = _this$props3.fetchModalDataSourceLoading,
          addDataGroupLoading = _this$props3.addDataGroupLoading,
          fetchDataGroupLoading = _this$props3.fetchDataGroupLoading,
          fetchModalDataGroupLoading = _this$props3.fetchModalDataGroupLoading;
      var _this$state4 = this.state,
          selectedRow = _this$state4.selectedRow,
          _this$state4$roleAuth = _this$state4.roleAuthScopeCode,
          roleAuthScopeCode = _this$state4$roleAuth === void 0 ? [] : _this$state4$roleAuth,
          key = _this$state4.key,
          currentAuthScope = _this$state4.currentAuthScope,
          authUserDefaultValue = _this$state4.authUserDefaultValue,
          roleAuth = _this$state4.roleAuth,
          _this$state4$authDefa = _this$state4.authDefaultValue,
          authDefaultValue = _this$state4$authDefa === void 0 ? [] : _this$state4$authDefa,
          _this$state4$enableCh = _this$state4.enableChangeList,
          enableChangeList = _this$state4$enableCh === void 0 ? [] : _this$state4$enableCh,
          _this$state4$msgChang = _this$state4.msgChangeList,
          msgChangeList = _this$state4$msgChang === void 0 ? [] : _this$state4$msgChang,
          _this$state4$scopeCha = _this$state4.scopeChangeList,
          scopeChangeList = _this$state4$scopeCha === void 0 ? [] : _this$state4$scopeCha,
          _this$state4$authChan = _this$state4.authChangeList,
          authChangeList = _this$state4$authChan === void 0 ? [] : _this$state4$authChan,
          isSiteFlag = _this$state4.isSiteFlag,
          content = _this$state4.content;
      var dataSource = this.mergeData(content, enableChangeList, msgChangeList, scopeChangeList, authChangeList);
      var bizRoleAuthorityLines = selectedRow.roleAuthorityLines && selectedRow.roleAuthorityLines.filter(function (item) {
        return item.dimensionType === 'BIZ';
      }) || [];
      var userRoleAuthorityLines = selectedRow.roleAuthorityLines && selectedRow.roleAuthorityLines.filter(function (item) {
        return item.dimensionType === 'USER';
      }) || [];
      var columns = [{
        title: intl.get('ciam.roleManagement.model.role.docType').d('单据'),
        dataIndex: 'docTypeName',
        width: 370
      }, {
        title: intl.get('ciam.roleManagement.model.role.authRang').d('权限维度范围'),
        width: 250,
        dataIndex: 'msgFlag',
        render: function render(_, record) {
          _this4.enabledFlag = null;
          scopeChangeList.forEach(function (i) {
            if (i.uuid === record.uuid) {
              _this4.enabledFlag = i.docEnabledFlag;
            }
          });
          _this4.isChanged = false;
          scopeChangeList.forEach(function (i) {
            if (i.uuid === record.uuid) {
              _this4.isChanged = true;
            }
          });
          return (
            /*#__PURE__*/
            // <CheckboxGroup value={record.authScopeCode} onChange={this.scopeOnChangeLater}>
            React.createElement(React.Fragment, null, roleAuthScopeCode.map(function (item) {
              return /*#__PURE__*/React.createElement(Checkbox // value={item.value}
              // key={item.value}
              , {
                checked: // eslint-disable-next-line no-nested-ternary
                record.authControlType === 'ONLY_CONFIG' ? 1 : null || _this4.isChanged && scopeChangeList.length > 0 ? _this4.enabledFlag : record.docEnabledFlag,
                disabled: record.authControlType === 'ONLY_CONFIG',
                style: {
                  marginRight: 0,
                  padding: '0 10px',
                  display: item.meaning === record.authScopeMeaning ? '' : 'none'
                },
                onChange: _this4.scopeOnChangeLater
              }, item.meaning);
            })) // </CheckboxGroup>

          );
        }
      }];
      var authDim = !_isEmpty(selectedRow) && (currentAuthScope === 'USER' ?
      /*#__PURE__*/
      // <RadioGroup
      //   value={authUserDefaultValue}
      //   onChange={this.authOnChange}
      //   style={{ width: '100%' }}
      // >
      //   <Row>
      //     {userRoleAuthorityLines.map((item) => (
      //       <Col span={24} key={item.authDimId}>
      //         <Radio onClick={this.authOnChange} value={item.authDimId} key={item.authDimId} style={{ height: 30 }}>
      //           {item.authTypeMeaning}
      //         </Radio>
      //       </Col>
      //     ))}
      //   </Row>
      // </RadioGroup>
      React.createElement(CheckboxGroup, {
        style: {
          width: '100%'
        },
        onChange: function onChange(e) {
          var dataClone = _cloneDeep(content);

          var sourceRow = dataClone.find(function (item) {
            return item[key] === selectedRow[key];
          }) || []; // 找到原始单据项

          var sourceList = sourceRow.roleAuthorityLines || []; // 查找原始 List

          sourceList.filter(function (item) {
            return item.authDimId === e[0];
          });

          _this4.authOnChange(sourceList.filter(function (item) {
            return item.authDimId === e[e.length - 1];
          })[0] || {});
        },
        value: authUserDefaultValue
      }, /*#__PURE__*/React.createElement(Row, null, userRoleAuthorityLines.map(function (item) {
        return /*#__PURE__*/React.createElement(Col, {
          span: 24,
          key: item.authDimId
        }, /*#__PURE__*/React.createElement(Checkbox, {
          style: {
            height: 30
          },
          key: item.authDimId,
          value: item.authDimId
        }, item.authTypeMeaning));
      }))) : /*#__PURE__*/React.createElement(CheckboxGroup, {
        style: {
          width: '100%'
        },
        onChange: this.authOnChange,
        value: authDefaultValue
      }, /*#__PURE__*/React.createElement(Row, null, bizRoleAuthorityLines.map(function (item) {
        return /*#__PURE__*/React.createElement(Col, {
          span: 24,
          key: item.authDimId
        }, /*#__PURE__*/React.createElement(Checkbox, {
          style: {
            height: 30
          },
          key: item.authDimId,
          value: item.authDimId
        }, item.authTypeMeaning));
      }))));
      var authDataProps = {
        path: path,
        dispatch: dispatch,
        tenantId: tenantId,
        roleId: roleId,
        roleDataAuthorityLovView: roleDataAuthorityLovView,
        roleDataAuthorityDataSource: roleDataAuthorityDataSource,
        roleDataAuthorityDataGroup: roleDataAuthorityDataGroup,
        roleDataAuthorityValueList: roleDataAuthorityValueList,
        authorityCompany: roleDataAuthorityCompany,
        authorityPurorg: roleDataAuthorityPurorg,
        authorityManagement: roleDataAuthorityManagement,
        authorityPuragent: roleDataAuthorityPuragent,
        fetchTabListLoading: fetchTabListLoading,
        // 公司loading
        updateCompanyLoading: updateCompanyLoading,
        fetchCompanyLoading: fetchCompanyLoading,
        refreshCompanyLoading: refreshCompanyLoading,
        // 采购组织loading
        addPurOrgLoading: addPurOrgLoading,
        fetchPurOrgLoading: fetchPurOrgLoading,
        fetchPurOrgModalLoading: fetchPurOrgModalLoading,
        // 采购员
        addPuragentLoading: addPuragentLoading,
        fetchPuragentLoading: fetchPuragentLoading,
        fetchModalPuragentLoading: fetchModalPuragentLoading,
        // 值集
        addValueListLoading: addValueListLoading,
        fetchValueListLoading: fetchValueListLoading,
        fetchModalValueListLoading: fetchModalValueListLoading,
        // 值集视图
        addLovViewLoading: addLovViewLoading,
        fetchLovViewLoading: fetchLovViewLoading,
        fetchModalLovViewLoading: fetchModalLovViewLoading,
        // 数据源
        addDataSourceLoading: addDataSourceLoading,
        fetchDataSourceLoading: fetchDataSourceLoading,
        fetchModalDataSourceLoading: fetchModalDataSourceLoading,
        // 数据组
        addDataGroupLoading: addDataGroupLoading,
        fetchDataGroupLoading: fetchDataGroupLoading,
        fetchModalDataGroupLoading: fetchModalDataGroupLoading
      };
      return /*#__PURE__*/React.createElement(Modal, {
        destroyOnClose: true,
        wrapClassName: "ant-modal-sidebar-right",
        transitionName: "move-right",
        title: title,
        width: "1200px",
        visible: modalVisible,
        confirmLoading: saveLoading,
        onCancel: this.handleCancel,
        onOk: this.handleOk
      }, isSiteFlag ? /*#__PURE__*/React.createElement(Row, {
        gutter: 24
      }, /*#__PURE__*/React.createElement(Col, {
        span: 16
      }, /*#__PURE__*/React.createElement(Form, null, /*#__PURE__*/React.createElement(Row, {
        type: "flex",
        gutter: 24,
        align: "bottom"
      }, /*#__PURE__*/React.createElement(Col, {
        span: 8
      }, /*#__PURE__*/React.createElement(Form.Item, Object.assign({}, SEARCH_FORM_ITEM_LAYOUT, {
        label: intl.get('ciam.roleManagement.model.role.docType').d('单据')
      }), form.getFieldDecorator('searchDocTypeName')( /*#__PURE__*/React.createElement(Input, null)))), /*#__PURE__*/React.createElement(Col, {
        span: 8
      }, /*#__PURE__*/React.createElement(Form.Item, SEARCH_FORM_ITEM_LAYOUT, /*#__PURE__*/React.createElement(Button, {
        type: "primary",
        htmlType: "submit",
        onClick: this.handleSearch
      }, intl.get('cpaas.common.button.search').d('查询')))))), /*#__PURE__*/React.createElement(Table, {
        bordered: true,
        rowKey: key,
        style: {
          marginTop: 16
        },
        rowClassName: this.addHighlight,
        onChange: this.handlePagination,
        onRow: function onRow(record) {
          return {
            onClick: function onClick() {
              return _this4.onRow(record);
            }
          };
        },
        dataSource: dataSource,
        columns: columns,
        scroll: {
          x: tableScrollWidth(columns)
        },
        loading: initLoading,
        hideDefaultSelections: true,
        pagination: _objectSpread(_objectSpread({}, createPagination(roleAuth)), {}, {
          simple: true
        })
      })), /*#__PURE__*/React.createElement(Col, {
        span: 8
      }, !_isEmpty(selectedRow) ? /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Row, null, /*#__PURE__*/React.createElement(Col, null, /*#__PURE__*/React.createElement("div", {
        style: {
          marginTop: 55,
          height: 48,
          lineHeight: '48px',
          borderRadius: '2px 2px 0 0',
          textAlign: 'center',
          border: '1px solid #e8e8e8',
          borderBottomColor: '#cecece',
          fontWeight: 'bold',
          background: '#f5f5f5'
        }
      }, intl.get('ciam.roleManagement.view.title.dimControl').d('控制维度')))), /*#__PURE__*/React.createElement(Row, null, /*#__PURE__*/React.createElement(Col, null, /*#__PURE__*/React.createElement("div", {
        style: {
          padding: '20px',
          border: '1px solid #e8e8e8',
          borderTopWidth: 0,
          minHeight: 350
        }
      }, authDim)))) : null)) : /*#__PURE__*/React.createElement(Tabs, {
        defaultActiveKey: "1",
        animated: false
      }, /*#__PURE__*/React.createElement(Tabs.TabPane, {
        key: "1",
        tab: intl.get('ciam.roleManagement.view.message.title.auth').d('权限维度')
      }, /*#__PURE__*/React.createElement(Row, {
        gutter: 24
      }, /*#__PURE__*/React.createElement(Col, {
        span: 16
      }, /*#__PURE__*/React.createElement(Form, null, /*#__PURE__*/React.createElement(Row, {
        type: "flex",
        gutter: 24,
        align: "bottom"
      }, /*#__PURE__*/React.createElement(Col, {
        span: 8
      }, /*#__PURE__*/React.createElement(Form.Item, Object.assign({}, SEARCH_FORM_ITEM_LAYOUT, {
        label: intl.get('ciam.roleManagement.model.role.docType').d('单据')
      }), form.getFieldDecorator('searchDocTypeName')( /*#__PURE__*/React.createElement(Input, null)))), /*#__PURE__*/React.createElement(Col, {
        span: 8
      }, /*#__PURE__*/React.createElement(Form.Item, SEARCH_FORM_ITEM_LAYOUT, /*#__PURE__*/React.createElement(Button, {
        type: "primary",
        htmlType: "submit",
        onClick: this.handleSearch
      }, intl.get('cpaas.common.button.search').d('查询')))))), /*#__PURE__*/React.createElement(Table, {
        bordered: true,
        rowKey: key,
        style: {
          marginTop: 16
        },
        rowClassName: this.addHighlight,
        onChange: this.handlePagination,
        onRow: function onRow(record) {
          return {
            onClick: function onClick() {
              return _this4.onRow(record);
            }
          };
        },
        dataSource: dataSource,
        columns: columns,
        scroll: {
          x: tableScrollWidth(columns)
        },
        loading: initLoading,
        hideDefaultSelections: true,
        pagination: _objectSpread(_objectSpread({}, createPagination(roleAuth)), {}, {
          simple: true
        })
      })), /*#__PURE__*/React.createElement(Col, {
        span: 8
      }, !_isEmpty(selectedRow) ? /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Row, null, /*#__PURE__*/React.createElement(Col, null, /*#__PURE__*/React.createElement("div", {
        style: {
          marginTop: 55,
          height: 48,
          lineHeight: '48px',
          borderRadius: '2px 2px 0 0',
          textAlign: 'center',
          border: '1px solid #e8e8e8',
          borderBottomColor: '#cecece',
          fontWeight: 'bold',
          background: '#f5f5f5'
        }
      }, intl.get('ciam.roleManagement.view.title.dimControl').d('控制维度')))), /*#__PURE__*/React.createElement(Row, null, /*#__PURE__*/React.createElement(Col, null, /*#__PURE__*/React.createElement("div", {
        style: {
          padding: '20px',
          border: '1px solid #e8e8e8',
          borderTopWidth: 0,
          minHeight: 350
        }
      }, authDim)))) : null))), /*#__PURE__*/React.createElement(Tabs.TabPane, {
        key: "2",
        tab: intl.get('ciam.roleManagement.view.message.title.authData').d('权限数据')
      }, /*#__PURE__*/React.createElement(AuthData, authDataProps))));
    }
  }], [{
    key: "getDerivedStateFromProps",
    value: function getDerivedStateFromProps(nextProps, prevState) {
      var prevSelectedRowKeys = prevState.selectedRowKeys;
      var roleAuth = nextProps.roleAuth,
          _nextProps$roleAuth$c = nextProps.roleAuth.content,
          content = _nextProps$roleAuth$c === void 0 ? [] : _nextProps$roleAuth$c,
          roleAuthScopeCode = nextProps.roleAuthScopeCode,
          roleAuthScopeTypeCode = nextProps.roleAuthScopeTypeCode; // 后端返回的数据中没有唯一标识，处理数据给一个唯一标识

      var stateContent = content.map(function (item) {
        return _objectSpread(_objectSpread({}, item), {}, {
          uuid: "".concat(item.authDocTypeId, "-").concat(item.authScopeCode)
        });
      });
      var selectedRowKeys = _isEmpty(prevSelectedRowKeys) ? content.filter(function (item) {
        return !!item.docEnabledFlag;
      }).map(function (item) {
        return item.authDocTypeId;
      }) : prevSelectedRowKeys;
      return _objectSpread(_objectSpread({}, prevState), {}, {
        roleAuth: roleAuth,
        content: stateContent,
        selectedRowKeys: selectedRowKeys,
        roleAuthScopeCode: roleAuthScopeCode,
        roleAuthScopeTypeCode: roleAuthScopeTypeCode
      });
    }
  }]);

  return AuthDrawer;
}(React.Component), (_applyDecoratedDescriptor(_class2.prototype, "handleCancel", [_dec3], Object.getOwnPropertyDescriptor(_class2.prototype, "handleCancel"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "handleOk", [_dec4], Object.getOwnPropertyDescriptor(_class2.prototype, "handleOk"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "onRow", [_dec5], Object.getOwnPropertyDescriptor(_class2.prototype, "onRow"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "addHighlight", [_dec6], Object.getOwnPropertyDescriptor(_class2.prototype, "addHighlight"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "handleSearch", [_dec7], Object.getOwnPropertyDescriptor(_class2.prototype, "handleSearch"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "handlePagination", [_dec8], Object.getOwnPropertyDescriptor(_class2.prototype, "handlePagination"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "resetState", [_dec9], Object.getOwnPropertyDescriptor(_class2.prototype, "resetState"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "scopeOnChangeLater", [_dec10], Object.getOwnPropertyDescriptor(_class2.prototype, "scopeOnChangeLater"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "scopeOnChange", [_dec11], Object.getOwnPropertyDescriptor(_class2.prototype, "scopeOnChange"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "authOnChange", [_dec12], Object.getOwnPropertyDescriptor(_class2.prototype, "authOnChange"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "mergeData", [_dec13], Object.getOwnPropertyDescriptor(_class2.prototype, "mergeData"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "createSaveData", [_dec14], Object.getOwnPropertyDescriptor(_class2.prototype, "createSaveData"), _class2.prototype)), _class2)) || _class) || _class);
export { AuthDrawer as default };